home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 2).ISO / mods / Q2_Codered / codeRED1_0.exe / Data1.cab / NPC_alien.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-20  |  8.1 KB  |  326 lines

  1. /*
  2. ==============================================================================
  3.  
  4. Martian npc_alien(General) and Commander Braddock.
  5.  
  6. ==============================================================================
  7. */
  8.  
  9. #include "g_local.h"
  10. #include "m_emporer.h"
  11.  
  12. static int sound_idle;
  13. static int sound_shoot;
  14. static int sound_plead;
  15. static int sound_rant;
  16. static int sound_soldier_die;
  17.  
  18.  
  19. void npc_alien_talk(edict_t *self);
  20. void npc_alien_shoot(edict_t *self);
  21. void npc_alien_death(edict_t *self);
  22. void npc_alien_escape(edict_t *self);
  23.  
  24. void breathe(edict_t *self)
  25. {
  26.     if (random() < 0.2)
  27.         gi.sound (self, CHAN_VOICE, sound_idle, 1 , ATTN_NORM, 0);
  28. }
  29.  
  30. mframe_t npc_alien_frames_stand [] =
  31. {
  32.     ai_stand, 0, breathe,
  33.     ai_stand, 0, NULL,
  34.     ai_stand, 0, NULL,
  35.     ai_stand, 0, NULL,
  36.     ai_stand, 0, NULL,
  37.     ai_stand, 0, NULL,
  38.     ai_stand, 0, NULL,
  39.     ai_stand, 0, NULL,
  40.     ai_stand, 0, NULL
  41.     
  42. };
  43. mmove_t npc_alien_move_stand = {FRAME_stand01, FRAME_stand09, npc_alien_frames_stand, NULL};
  44.  
  45. void npc_alien_stand (edict_t *self)
  46. {
  47.     self->monsterinfo.currentmove = &npc_alien_move_stand;
  48. }
  49.  
  50. void alien_talk (edict_t *self)
  51. {
  52.     gi.sound (self, CHAN_VOICE, sound_rant, 1, ATTN_NORM, 0);
  53. }
  54.  
  55. mframe_t npc_alien_frames_talk3 [] =
  56. {
  57.  
  58.     ai_move, 0, NULL,
  59.     ai_move, 0, NULL,
  60.     ai_move, 0, NULL,
  61.     ai_move, 0, NULL,
  62.     ai_move, 0, NULL,
  63.     ai_move, 0, NULL,
  64.     ai_move, 0, NULL,
  65.     ai_move, 0, NULL,
  66.     ai_move, 0, NULL
  67. };
  68. mmove_t npc_alien_move_talk3 = {FRAME_stand01, FRAME_stand09, npc_alien_frames_talk3, npc_alien_shoot};
  69.  
  70. void npc_alien_talk3 (edict_t *self)
  71. {
  72.     self->monsterinfo.currentmove = &npc_alien_move_talk3;
  73. }
  74.  
  75. mframe_t npc_alien_frames_talk2 [] =
  76. {
  77.  
  78.     ai_move, 0, NULL,
  79.     ai_move, 0, NULL,
  80.     ai_move, 0, NULL,
  81.     ai_move, 0, NULL,
  82.     ai_move, 0, NULL,
  83.     ai_move, 0, NULL,
  84.     ai_move, 0, NULL,
  85.     ai_move, 0, NULL,
  86.     ai_move, 0, NULL
  87. };
  88. mmove_t npc_alien_move_talk2 = {FRAME_stand01, FRAME_stand09, npc_alien_frames_talk2, npc_alien_talk3};
  89.  
  90. void npc_alien_talk2 (edict_t *self)
  91. {
  92.     self->monsterinfo.currentmove = &npc_alien_move_talk2;
  93. }
  94.  
  95. mframe_t npc_alien_frames_talk [] =
  96. {
  97.  
  98.     ai_move, 0, NULL,
  99.     ai_move, 0, NULL,
  100.     ai_move, 0, NULL,
  101.     ai_move, 0, NULL,
  102.     ai_move, 0, NULL,
  103.     ai_move, 0, NULL,
  104.     ai_move, 0, NULL,
  105.     ai_move, 0, NULL,
  106.     ai_move, 0, NULL
  107. };
  108. mmove_t npc_alien_move_talk = {FRAME_stand01, FRAME_stand09, npc_alien_frames_talk, npc_alien_talk2};
  109.  
  110. void npc_alien_talk (edict_t *self)
  111. {
  112.     vec3_t    forward, right, start;
  113.  
  114.     AngleVectors (self->s.angles, forward, right, NULL);
  115.     G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_MAKRON_BFG], forward, right, start);
  116.     VectorCopy (self->s.origin, start);
  117.     forward[0] = forward[0] * 52;
  118.     forward[1] = forward[1] * 52;
  119.     VectorAdd(self->s.origin, forward, self->s.origin);
  120.  
  121.     gi.sound (self, CHAN_VOICE, sound_plead, 1 , ATTN_NORM, 0);
  122.  
  123.     VectorCopy (start, self->s.origin);
  124.  
  125.     self->monsterinfo.currentmove = &npc_alien_move_talk;
  126. }
  127.  
  128. void npc_alien_blaster (edict_t *self)
  129. {
  130.     vec3_t    forward, right;
  131.     vec3_t    start;
  132.     vec3_t    end;
  133.     vec3_t    dir;
  134.     int        flash_number = MZ2_MAKRON_BFG;
  135.     
  136.     AngleVectors (self->s.angles, forward, right, NULL);
  137.     G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  138.     VectorCopy (self->s.origin, start);
  139.     VectorCopy (self->enemy->s.origin, end);
  140.     end[2] += 16;
  141.     VectorSubtract (end, start, dir);
  142.     right[0] = right[0] * 4;
  143.     right[1] = right[1] * 4;
  144.     forward[0] = forward[0] * 64;
  145.     forward[1] = forward[1] * 64;
  146.     VectorAdd(start, right, start);
  147.     VectorAdd(end, forward, end);
  148.     start[2] = start[2] + 4;
  149.         
  150.     gi.WriteByte (svc_temp_entity);
  151.     gi.WriteByte (TE_LEADERBLASTER);
  152.     gi.WritePosition (start);
  153.     gi.WritePosition (end);
  154.     gi.multicast (start, MULTICAST_PHS); 
  155.     
  156.     gi.sound (self, CHAN_VOICE, sound_shoot, 1, ATTN_NORM, 0);
  157.     
  158.     gi.WriteByte (svc_temp_entity);
  159.     gi.WriteByte (TE_BLASTER);
  160.     gi.WritePosition (end);
  161.     gi.WriteDir (dir);
  162.     gi.multicast (start, MULTICAST_PVS);
  163. }
  164.  
  165. void remove_braddock (edict_t *self)
  166. {
  167.     int n; 
  168.     vec3_t    forward, right, start;
  169.     
  170.     gi.sound (self, CHAN_VOICE, sound_soldier_die, 1, ATTN_NORM, 0);
  171.     AngleVectors (self->s.angles, forward, right, NULL);
  172.     G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_MAKRON_BFG], forward, right, start);
  173.     VectorCopy (self->s.origin, start);
  174.     forward[0] = forward[0] * 52;
  175.     forward[1] = forward[1] * 52;
  176.     VectorAdd(self->s.origin, forward, self->s.origin);
  177.         
  178.     gi.WriteByte (svc_temp_entity);
  179.     gi.WriteByte (TE_EXPLOSION1);
  180.     gi.WritePosition (self->s.origin);
  181.     gi.multicast (self->s.origin, MULTICAST_PVS);
  182.  
  183.     for (n= 0; n < 4; n++)
  184.         ThrowGib (self, "models/objects/gibs/bone/tris.md2", 100, GIB_ORGANIC, EF_GIB);
  185.     for (n= 0; n < 4; n++)
  186.         ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", 100, GIB_ORGANIC, EF_GIB);
  187.  
  188.     self->s.modelindex3 = 0;
  189.     
  190.     VectorCopy(start, self->s.origin);
  191. }
  192.  
  193. mframe_t npc_alien_frames_shoot [] =
  194. {
  195.     
  196.     ai_move, 0, NULL,
  197.     ai_move, 0, NULL,
  198.     ai_move, 0, NULL,
  199.     ai_move, 0, NULL,
  200.     ai_move, 0, NULL,
  201.     ai_move, 0, NULL,
  202.     ai_move, 0, npc_alien_blaster,
  203.     ai_move, 0, NULL,
  204.     ai_move, 0, NULL,
  205.     ai_move, 0, remove_braddock
  206. };
  207. mmove_t npc_alien_move_shoot = {FRAME_attack01, FRAME_attack10, npc_alien_frames_shoot, npc_alien_death};
  208.  
  209. void npc_alien_shoot (edict_t *self)
  210. {
  211.     self->monsterinfo.currentmove = &npc_alien_move_shoot;
  212. }
  213.  
  214. mframe_t npc_alien_frames_death [] =
  215. {
  216.     
  217.     ai_move, 0, alien_talk,
  218.     ai_move, 0, NULL,
  219.     ai_move, 0, NULL,
  220.     ai_move, 0, NULL,
  221.     ai_move, 0, NULL,
  222.     ai_move, 0, NULL,
  223.     ai_move, 0, NULL,
  224.     ai_move, 0, NULL,
  225.     ai_move, 0, NULL,
  226.     ai_move, 0, NULL,
  227.     ai_move, 0, NULL,
  228.     ai_move, 0, NULL,
  229.     ai_move, 0, NULL
  230. };
  231. mmove_t npc_alien_move_death = {FRAME_rant01, FRAME_rant13, npc_alien_frames_death, npc_alien_escape};
  232.  
  233. void npc_alien_death (edict_t *self)
  234. {
  235.     self->monsterinfo.currentmove = &npc_alien_move_death;
  236. }
  237.  
  238. void npc_alien_dead (edict_t *self)
  239. {
  240.     self->s.modelindex = 0;
  241.     self->s.solid = SOLID_NOT;
  242.     self->deadflag = DEAD_DEAD;
  243.     self->takedamage = DAMAGE_NO;
  244.     self->movetype = MOVETYPE_TOSS;
  245.     self->svflags |= SVF_DEADMONSTER;
  246.     self->nextthink = 0;
  247.     gi.linkentity (self);
  248.  
  249.     gi.WriteByte (svc_temp_entity);
  250.     gi.WriteByte (TE_BOSSTPORT);
  251.     gi.WritePosition (self->s.origin);
  252.     gi.multicast (self->s.origin, MULTICAST_PVS);
  253. }
  254.  
  255. mframe_t npc_alien_frames_escape [] =
  256. {
  257.  
  258.     ai_move, 0, NULL,
  259.     ai_move, 0, NULL,
  260.     ai_move, 0, NULL,
  261.     ai_move, 0, NULL,
  262.     ai_move, 0, NULL,
  263.     ai_move, 0, NULL,
  264.     ai_charge, 0, NULL,
  265.     ai_charge, 0, NULL,
  266.     ai_charge, 0, NULL
  267. };
  268. mmove_t npc_alien_move_escape = {FRAME_stand01, FRAME_stand09, npc_alien_frames_escape, npc_alien_dead};
  269.  
  270. void npc_alien_escape (edict_t *self)
  271. {
  272.     self->monsterinfo.currentmove = &npc_alien_move_escape;
  273. }
  274.  
  275. void SP_npc_alien (edict_t *self)
  276. {
  277.     if (deathmatch->value)
  278.     {
  279.         G_FreeEdict (self);
  280.         return;
  281.     }
  282.  
  283.     // pre-caches
  284.  
  285.     sound_shoot = gi.soundindex ("martian/shoot2.wav");
  286.     sound_rant = gi.soundindex ("martian/ack2.wav");
  287.      sound_idle = gi.soundindex ("soldier/braddock_breath.wav");
  288.     sound_plead = gi.soundindex ("soldier/braddock_plead.wav");
  289.     sound_soldier_die = gi.soundindex("soldier/death.wav");
  290.     
  291.     self->s.modelindex = gi.modelindex("models/monsters/martian_ambass/tris.md2");
  292.     self->s.modelindex2 = gi.modelindex ("models/monsters/helmet/tris2.md2");
  293.     self->s.modelindex3 = gi.modelindex ("models/npc/braddock/tris.md2");
  294.  
  295.     VectorSet (self->mins, -16, -16, -26);
  296.     VectorSet (self->maxs, 16, 16, 48);
  297.     self->movetype = MOVETYPE_STEP;
  298.     self->solid = SOLID_BBOX;
  299.     self->s.skinnum = 0;
  300.     
  301.     self->max_health = 2500;
  302.     self->health = self->max_health;
  303.     self->gib_health = 0;
  304.     self->mass = 450;
  305.  
  306.     self->classname = "monster_martian_leader";
  307.  
  308.     self->pain = NULL;
  309.     self->die = NULL;
  310.  
  311.     self->monsterinfo.stand = npc_alien_stand;
  312.     self->monsterinfo.walk = npc_alien_talk;
  313.     self->monsterinfo.run = npc_alien_talk;
  314.     self->monsterinfo.dodge = NULL;
  315.     self->monsterinfo.attack = NULL;
  316.     self->monsterinfo.melee = NULL;
  317.     self->monsterinfo.sight = NULL;
  318.     self->monsterinfo.search = NULL;
  319.  
  320.     self->monsterinfo.currentmove = &npc_alien_move_stand;
  321.     self->monsterinfo.scale = MODEL_SCALE;
  322.  
  323.     gi.linkentity (self);
  324.  
  325.     walkmonster_start (self);
  326. }